/*
 * @Author: tansq
 * @Date: 2021-09-07 08:27:00
 * @LastEditTime: 2022-09-13 09:31:09
 * @LastEditors: tansq
 * @Description: 公司库公共资源
 * @FilePath: \hte-vue-dev\src\views\library\company\companyMixin.js
 * @可以输入预定的版权声明、个性签名、空行等
 */


import { deleteAction, getAction,postAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
import { codeInfoList } from "@/api/codeInfo"
import cloneDeep from 'lodash/cloneDeep'
import { isDateYYYYMMDD,isNumber,isArea,isNumberOrFload } from '@/utils/validate'
import Vue from 'vue'
import { ACCESS_TOKEN, TENANT_ID } from "@/store/mutation-types"
import store from '@/store'
const DICS_TYPE = {indexNameType:'公司库规模指标名称',unitType:'公司库规模单位',sizeType:'公司库规模类型',companyType:'公司库公司类型',companyCategory:'公司库公司类别',companyTeam:'公司库主要人员',
  industryList : '行业类型',qualification: '企业资质'}
export const companyMixin = {
    data(){
      return {
        
       dics:{
         industry: [],
         indexNameType: [],
         unitType: [],
         sizeType: [],
         companyType: [],
         companyCategory: [],
         status: [],
         registeredCapitalUnit: [],
         companyClass: [],
         companyClassDetails: [],
         natureOfCompany: [],
         companyTeam: [],
         flagDics: [{ code: '否', name: '否' }, { code: '是', name: '是' }],
         qualification: []
       },
   

      }
    
    },
    mounted () {
        this.initDics();  
        
    },
    methods:{
      initDics(){
          let that = this;
          var param = {type:DICS_TYPE.indexNameType,column:"code",order:"Asc",pageNo:0,pageSize:-1}          
        codeInfoList(cloneDeep(Object.assign(param,{type:DICS_TYPE.indexNameType})) ).then( res=>{
            that.dics.indexNameType = res.result.records

        })
       
        codeInfoList(cloneDeep(Object.assign(param,{type:DICS_TYPE.unitType}) ) ).then( res=>{
            that.dics.unitType = res.result.records

        })
        
        codeInfoList( cloneDeep( Object.assign(param,{type:DICS_TYPE.sizeType}) )).then( res=>{
            that.dics.sizeType = res.result.records

        })
        
        codeInfoList(cloneDeep(Object.assign(param,{type:DICS_TYPE.companyType})) ).then( res=>{
            that.dics.companyType = res.result.records

        })
        
        // codeInfoList(cloneDeep( Object.assign(param,{type:DICS_TYPE.companyCategory}))).then( res=>{
        //     that.dics.companyCategory = res.result.records

        // })


        codeInfoList(cloneDeep( Object.assign(param,{type:'公司库注册资金单位'}))).then( res=>{
            that.dics.registeredCapitalUnit = res.result.records

        })
        codeInfoList(cloneDeep( Object.assign(param,{type:'公司库企业状态'}))).then( res=>{
            that.dics.status = res.result.records

        })
        codeInfoList(cloneDeep( Object.assign(param,{type:'公司库分类首页'}))).then( res=>{
            that.dics.companyClass = res.result.records

        })
        codeInfoList(cloneDeep( Object.assign(param,{type:'公司库分类明细'}))).then( res=>{
            that.dics.companyClassDetails = res.result.records

        })
        codeInfoList(cloneDeep( Object.assign(param,{type:'公司库性质'}))).then( res=>{
            that.dics.natureOfCompany = res.result.records

        })

        codeInfoList(cloneDeep( Object.assign(param,{type:DICS_TYPE.companyTeam}))).then( res=>{
            that.dics.companyTeam = res.result.records
        })

        codeInfoList(cloneDeep( Object.assign(param,{type:DICS_TYPE.industryList}))).then( res=>{
          that.dics.industry = res.result.records
        })

        codeInfoList(cloneDeep( Object.assign(param,{type:DICS_TYPE.qualification}))).then( res=>{
          that.dics.qualification = res.result.records
        })


        // getAction('/libraryCompany/hteLibCompanySize/industryNameList',{}).then(res=>{
        //     that.dics.industryName = res.result.records
        // });
      },
      
       

    }
}

//数据验证
export const companyValidate = {
    checkCompanyData(vm,data){
        //公司数据验证
        let that = vm
        var companyName = data.name;
        if(!companyName){
            vm.$message.warning(`操作异常:公司名称为空`);
            return false;
        }
        
       
        let status  = vm.dics.status.find(item=>{return item.name == data.statusName })  
       
        if(!status ){
            vm.$message.warning(`操作异常:${companyName}公司状态不存在${data.statusName}`);
            return false;    
        }  
         data.status = status.code;
        let size  = vm.dics.sizeType.find(item=>{return item.name == data.size })  
        
        if(!size ){
            vm.$message.warning(`操作异常:${companyName}公司规模不存在${data.size}`);
            return false;    
        }  

        let registeredCapitalUnit  = vm.dics.registeredCapitalUnit.find(item=>{return item.name == data.registeredCapitalUnitName })  
        
        if(!registeredCapitalUnit ){
            vm.$message.warning(`操作异常:${companyName}公司单位不存在${data.registeredCapitalUnitName}`);
            return false;    
        }  
        data.registeredCapitalUnit = registeredCapitalUnit.code

        let companyType  = vm.dics.companyType.find(item=>{return item.name == data.typeName })  
        
        if(!companyType ){
            vm.$message.warning(`操作异常:${companyName}公司类型不存在${data.typeName}`);
            return false;    
        }  
        data.type = companyType.code

        let industryName  = vm.dics.industry.find(item=>{return item.name == data.industryName })  
        
        if(!industryName ){
            vm.$message.warning(`操作异常:${companyName}行业分类不存在${data.industryName}`);
            return false;    
        }  
        data.industry = industryName.code
         let companyClassName  = vm.dics.companyClass.find(item=>{return item.name == data.companyClassName })  
        
        if(!companyClassName ){
            vm.$message.warning(`操作异常:${companyName}公司分类首页不存在${data.companyClassName}`);
            return false;    
        }  
        data.companyClass = companyClassName.code
         let companyClassDetailsName  = vm.dics.companyClassDetails.find(item=>{return item.name == data.companyClassDetailsName })  
        
        if(!companyClassDetailsName ){
            vm.$message.warning(`操作异常:${companyName}公司分类明细不存在${data.companyClassDetailsName}`);
            return false;    
        }  
        data.companyClassDetails = companyClassDetailsName.code

        //   let natureOfCompanyName  = vm.dics.natureOfCompany.find(item=>{return item.name == data.natureOfCompanyName })  
        
        // if(!natureOfCompanyName ){
        //     vm.$message.warning(`操作异常:${companyName}公司性质不存在${data.natureOfCompanyName}`);
        //     return false;    
        // }  
        // data.natureOfCompany = natureOfCompanyName.code

        if(!isDateYYYYMMDD(data.establishTime) || !isDateYYYYMMDD(data.approvalTime) ){
             vm.$message.warning(`操作异常:${companyName}成立日期、核准时间请导入正确的时间格式如下{2021-08-30}！`);
            return false; 
        }
        if(!data.businessTermLong){
            data.businessTermLong = '否'
            
        }
        let businessTermLong  = vm.dics.flagDics.find(item=>{return item.name == data.businessTermLong }) 
        if(!businessTermLong){
            vm.$message.warning(`操作异常:${companyName}是否长期营业${data.businessTermLong }请导入正确内容{是}{否}！`);
            return false;      
        }
        if(data.businessTermLong == '是'){
            data.businessTerm = null
        }
        if(data.businessTermLong == '否'  && !isDateYYYYMMDD(data.businessTerm))  {
            vm.$message.warning(`操作异常:${companyName}营业期限请导入正确的时间格式如下{2021-08-30}！`);
            return false; 
        }  
        if(!isArea(data.addressAreaLabel)){
             vm.$message.warning(`操作异常:${companyName}请导入地区格式如下{中国/广东省}！`);
            return false; 
        }
        if(!that.$refs.areaSelect.checkDataByLabel(data.addressAreaLabel)) return false;
        data.addressArea = that.$refs.areaSelect.getValueOrLabel(data.addressAreaLabel,'value')
                
        if(!isNumberOrFload(data.registeredCapital,1,2)){
            vm.$message.warning(`操作异常:注册资金请输入两位小数数字`);
            return false; 
        }

         return true;
      },
      checkCompanySizeInfoData(vm,data,companyName = ''){
        let that = vm
        //企业规模信息
        if(!!data.pclNumber&&!isNumber(data.pclNumber) || !!data.totalDomesticPatents&& !isNumber(data.totalDomesticPatents) || !!data.domesticInventionPatent&&!isNumber(data.domesticInventionPatent) 
            || !!data.domesticUtilityModel&& !isNumber(data.domesticUtilityModel) || !!data.softwareCopyright&&!isNumber(data.softwareCopyright) ){
            vm.$message.warning(`操作异常:${companyName}PCT专利、国内专利总数、国内发明专利、国内实用新型、软件著作权请输入数字`);
            return false; 
        }

         return true;
      },
      checkCompanyShareholderData(vm,data,companyName = ''){
        //股东信息验证
        let that = vm
        if(!data.name){
            vm.$message.warning(`操作异常:${companyName} 请输入股东名称`);
            return false;     
        }
        if(!!data.proportion &&  !isNumberOrFload(data.proportion,1,2) ){
            vm.$message.warning(`操作异常: ${companyName} 占比请输入两位小数数字`);
            return false; 
        }

         return true;
      },
      checkCompanyTeamData(vm,data,companyName = ''){
          //主要人员验证
          let that = vm
         if(!data.typeName){
            vm.$message.warning(`操作异常: ${companyName} 请输入职务`);
            return false; 
         }   
         let companyTeam  = vm.dics.companyTeam.find(item=>{return item.name == data.typeName })  
         
         if(!companyTeam){
             vm.$message.warning(`操作异常: ${companyName+data.typeName} 职务不存在`);
            return false; 
         }
         data.type =  companyTeam.code  
         return true;
      },
      checkCompanyHoldingParticipationData(vm,data,companyName = ''){
          //控股参股验证
          let that = vm
        if(!data.companyName){
           vm.$message.warning(`操作异常: ${companyName + data.companyName}请输入控股参股公司名称`);
           return false; 
        }  
        if(!!data.proportion && !isNumberOrFload(data.proportion,1,2) ){
            vm.$message.warning(`操作异常: ${companyName}占比请输入两位小数数字`);
            return false; 
         }  
        return true;
     }
 }